<template>
  <div>
    <!-- 3.导航 -->
    <div class="navs">
      <span
        v-for="(item,index) in nav"
        :key="item"
        :class="index==n?'select':''"
        @click="n=index"
      >{{item}}</span>
    </div>
    <!-- 5.展示列表 -->
    <div v-if="arr.length>0">
      <div
        class="item "
        @click="$router.push('/detail/'+item.id)"
        v-for="item in arr[n].content"
        :key="item.id"
      >
        <div class="fl">
          <img class="img" :src="$pre+item.img" alt />
        </div>
        <div class="fl" style="margin:0.5rem ">
          <h3>{{item.goodsname}}</h3>
          <div style="color:red">price:{{item.price}}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { reqHomeGoods } from "../../../http/api";
export default {
  data() {
    return {
      // 1.导航数据
      nav: ["热门推荐", "抢购", "全部"],
      n: 0,
      // 2.初始化数据
      arr: [],
    };
  },
  mounted() {
    // 4.请数据
    reqHomeGoods().then((res) => {
      this.arr = res.data.list;
    });
  },
};
</script>

<style scoped>
.navs {
  display: flex;
}
.navs span {
  flex: 1;
  text-align: center;
  line-height: 0.6rem;
}
.navs .select {
  color: #ff4400;
}
.item {
  margin: 0.2rem;
  border: 2px solid #ccc;
  overflow: hidden;
  /* background: pink; */
}
.img {
  width: 2rem;
  /* height: 3rem; */
}
.fl{
    float: left;
}
</style>